package com.itkongxiaoyi.controller;

import com.itkongxiaoyi.entity.PageBean;
import com.itkongxiaoyi.entity.Result;
import com.itkongxiaoyi.entity.Student;

import com.itkongxiaoyi.entity.StudentQueryParam;
import com.itkongxiaoyi.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
/**
 * 学生管理控制器
 */
@RestController
@RequestMapping("/api/student")
public class StudentController {

    @Autowired
    private StudentService studentService;
    /**
     * 添加学生
     */
    @PostMapping("/import")
    public Result save(@RequestBody Student student){
        studentService.save(student);
        return Result.success();
    }
    /*
    * 分页查询
     */
    @GetMapping("/page")
    public Result page(StudentQueryParam param){
        log.info("分页查询：{}, {}, {},{}, {}, {}, {}",
                param.getName(), param.getGender(), param.getAdmissionYear(), param.getCollege(),param.getMajor(), param.getPage(), param.getPageSize());
        PageBean pageBean = studentService.page(param);
        return Result.success(pageBean);
    }
    /*
    * 删除学生
     */
    @DeleteMapping
    public Result delete(@RequestParam List<Integer> ids){
        log.info("删除学生：{}", ids);
        studentService.delete(ids);
        return Result.success();
    }
    @GetMapping("/query/{id}")
    public Result getById(@PathVariable Integer id){
        log.info("回显员工，id = {}", id);
        Student student = studentService.getById(id);
        return Result.success(student);

    }

    @PutMapping
    public Result update(@RequestBody Student  student) {
        log.info("修改员工：emp={}", student);
        studentService.update(student);
        return Result.success();
    }
}

